<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Caffe: include/caffe/blob.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Caffe
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_4b7f3da7c7b4301d805dae0326fb91b7.html">caffe</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">blob.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef CAFFE_BLOB_HPP_</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#define CAFFE_BLOB_HPP_</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;</div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &lt;algorithm&gt;</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="preprocessor">#include &lt;vector&gt;</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#include &quot;caffe/common.hpp&quot;</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#include &quot;caffe/proto/caffe.pb.h&quot;</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#include &quot;caffe/syncedmem.hpp&quot;</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;</div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="keyword">const</span> <span class="keywordtype">int</span> kMaxBlobAxes = 32;</div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;</div><div class="line"><a name="l00014"></a><span class="lineno"><a class="line" href="namespacecaffe.html">   14</a></span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacecaffe.html">caffe</a> {</div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00024"></a><span class="lineno"><a class="line" href="classcaffe_1_1Blob.html">   24</a></span>&#160;<span class="keyword">class </span><a class="code" href="classcaffe_1_1Blob.html">Blob</a> {</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;  <a class="code" href="classcaffe_1_1Blob.html">Blob</a>()</div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;       : data_(), diff_(), count_(0), capacity_(0) {}</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;  <span class="keyword">explicit</span> <a class="code" href="classcaffe_1_1Blob.html">Blob</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Blob.html#a80ed3eddf98ffd408e9a627b1a7c2a9e">num</a>, <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Blob.html#ae48c8e9f0a0b66b041e47bf37ed04471">channels</a>, <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Blob.html#a18af535af43f4e9f85bd1e520886276f">height</a>,</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;      <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Blob.html#afbdc067c69e6b9bd6880a73c13db2ec6">width</a>);</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;  <span class="keyword">explicit</span> <a class="code" href="classcaffe_1_1Blob.html">Blob</a>(<span class="keyword">const</span> vector&lt;int&gt;&amp; shape);</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Blob.html#ad0e0a9a4f49478e89161c6afe4e341a0">Reshape</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> num, <span class="keyword">const</span> <span class="keywordtype">int</span> channels, <span class="keyword">const</span> <span class="keywordtype">int</span> height,</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;      <span class="keyword">const</span> <span class="keywordtype">int</span> width);</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Blob.html#ad0e0a9a4f49478e89161c6afe4e341a0">Reshape</a>(<span class="keyword">const</span> vector&lt;int&gt;&amp; shape);</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Blob.html#ad0e0a9a4f49478e89161c6afe4e341a0">Reshape</a>(<span class="keyword">const</span> BlobShape&amp; shape);</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;  <span class="keywordtype">void</span> ReshapeLike(<span class="keyword">const</span> <a class="code" href="classcaffe_1_1Blob.html">Blob</a>&amp; other);</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">string</span> shape_string()<span class="keyword"> const </span>{</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;    ostringstream stream;</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; shape_.size(); ++i) {</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;      stream &lt;&lt; shape_[i] &lt;&lt; <span class="stringliteral">&quot; &quot;</span>;</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    }</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    stream &lt;&lt; <span class="stringliteral">&quot;(&quot;</span> &lt;&lt; count_ &lt;&lt; <span class="stringliteral">&quot;)&quot;</span>;</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    <span class="keywordflow">return</span> stream.str();</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;  }</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;  <span class="keyword">inline</span> <span class="keyword">const</span> vector&lt;int&gt;&amp; shape()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> shape_; }</div><div class="line"><a name="l00071"></a><span class="lineno"><a class="line" href="classcaffe_1_1Blob.html#a807f4da98e8e0d1f60badb1f540fe010">   71</a></span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Blob.html#a807f4da98e8e0d1f60badb1f540fe010">shape</a>(<span class="keywordtype">int</span> index)<span class="keyword"> const </span>{</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;    <span class="keywordflow">return</span> shape_[<a class="code" href="classcaffe_1_1Blob.html#ad686f5ed9994046f2c741bfa81118509">CanonicalAxisIndex</a>(index)];</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;  }</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">int</span> num_axes()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> shape_.size(); }</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">int</span> count()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> count_; }</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;</div><div class="line"><a name="l00085"></a><span class="lineno"><a class="line" href="classcaffe_1_1Blob.html#a8674686a97c961b309b4420ead6626b5">   85</a></span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Blob.html#a8674686a97c961b309b4420ead6626b5">count</a>(<span class="keywordtype">int</span> start_axis, <span class="keywordtype">int</span> end_axis)<span class="keyword"> const </span>{</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    CHECK_LE(start_axis, end_axis);</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;    CHECK_GE(start_axis, 0);</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;    CHECK_GE(end_axis, 0);</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    CHECK_LE(start_axis, num_axes());</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;    CHECK_LE(end_axis, num_axes());</div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;    <span class="keywordtype">int</span> count = 1;</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = start_axis; i &lt; end_axis; ++i) {</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;      count *= shape(i);</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;    }</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;    <span class="keywordflow">return</span> count;</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;  }</div><div class="line"><a name="l00103"></a><span class="lineno"><a class="line" href="classcaffe_1_1Blob.html#aab573b2a70c26bf3b2ae65e42706003e">  103</a></span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Blob.html#aab573b2a70c26bf3b2ae65e42706003e">count</a>(<span class="keywordtype">int</span> start_axis)<span class="keyword"> const </span>{</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;    <span class="keywordflow">return</span> count(start_axis, num_axes());</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;  }</div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;</div><div class="line"><a name="l00118"></a><span class="lineno"><a class="line" href="classcaffe_1_1Blob.html#ad686f5ed9994046f2c741bfa81118509">  118</a></span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Blob.html#ad686f5ed9994046f2c741bfa81118509">CanonicalAxisIndex</a>(<span class="keywordtype">int</span> axis_index)<span class="keyword"> const </span>{</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;    CHECK_GE(axis_index, -num_axes())</div><div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;        &lt;&lt; <span class="stringliteral">&quot;axis &quot;</span> &lt;&lt; axis_index &lt;&lt; <span class="stringliteral">&quot; out of range for &quot;</span> &lt;&lt; num_axes()</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;        &lt;&lt; <span class="stringliteral">&quot;-D Blob with shape &quot;</span> &lt;&lt; shape_string();</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;    CHECK_LT(axis_index, num_axes())</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;        &lt;&lt; <span class="stringliteral">&quot;axis &quot;</span> &lt;&lt; axis_index &lt;&lt; <span class="stringliteral">&quot; out of range for &quot;</span> &lt;&lt; num_axes()</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;        &lt;&lt; <span class="stringliteral">&quot;-D Blob with shape &quot;</span> &lt;&lt; shape_string();</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;    <span class="keywordflow">if</span> (axis_index &lt; 0) {</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;      <span class="keywordflow">return</span> axis_index + num_axes();</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;    }</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;    <span class="keywordflow">return</span> axis_index;</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;  }</div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;</div><div class="line"><a name="l00132"></a><span class="lineno"><a class="line" href="classcaffe_1_1Blob.html#a80ed3eddf98ffd408e9a627b1a7c2a9e">  132</a></span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Blob.html#a80ed3eddf98ffd408e9a627b1a7c2a9e">num</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> LegacyShape(0); }</div><div class="line"><a name="l00134"></a><span class="lineno"><a class="line" href="classcaffe_1_1Blob.html#ae48c8e9f0a0b66b041e47bf37ed04471">  134</a></span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Blob.html#ae48c8e9f0a0b66b041e47bf37ed04471">channels</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> LegacyShape(1); }</div><div class="line"><a name="l00136"></a><span class="lineno"><a class="line" href="classcaffe_1_1Blob.html#a18af535af43f4e9f85bd1e520886276f">  136</a></span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Blob.html#a18af535af43f4e9f85bd1e520886276f">height</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> LegacyShape(2); }</div><div class="line"><a name="l00138"></a><span class="lineno"><a class="line" href="classcaffe_1_1Blob.html#afbdc067c69e6b9bd6880a73c13db2ec6">  138</a></span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Blob.html#afbdc067c69e6b9bd6880a73c13db2ec6">width</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> LegacyShape(3); }</div><div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">int</span> LegacyShape(<span class="keywordtype">int</span> index)<span class="keyword"> const </span>{</div><div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;    CHECK_LE(num_axes(), 4)</div><div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;        &lt;&lt; <span class="stringliteral">&quot;Cannot use legacy accessors on Blobs with &gt; 4 axes.&quot;</span>;</div><div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;    CHECK_LT(index, 4);</div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;    CHECK_GE(index, -4);</div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;    <span class="keywordflow">if</span> (index &gt;= num_axes() || index &lt; -num_axes()) {</div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;      <span class="comment">// Axis is out of range, but still in [0, 3] (or [-4, -1] for reverse</span></div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;      <span class="comment">// indexing) -- this special case simulates the one-padding used to fill</span></div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;      <span class="comment">// extraneous axes of legacy blobs.</span></div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;      <span class="keywordflow">return</span> 1;</div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;    }</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;    <span class="keywordflow">return</span> shape(index);</div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;  }</div><div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;</div><div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">int</span> offset(<span class="keyword">const</span> <span class="keywordtype">int</span> n, <span class="keyword">const</span> <span class="keywordtype">int</span> c = 0, <span class="keyword">const</span> <span class="keywordtype">int</span> h = 0,</div><div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;      <span class="keyword">const</span> <span class="keywordtype">int</span> w = 0)<span class="keyword"> const </span>{</div><div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;    CHECK_GE(n, 0);</div><div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;    CHECK_LE(n, <a class="code" href="classcaffe_1_1Blob.html#a80ed3eddf98ffd408e9a627b1a7c2a9e">num</a>());</div><div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;    CHECK_GE(<a class="code" href="classcaffe_1_1Blob.html#ae48c8e9f0a0b66b041e47bf37ed04471">channels</a>(), 0);</div><div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;    CHECK_LE(c, <a class="code" href="classcaffe_1_1Blob.html#ae48c8e9f0a0b66b041e47bf37ed04471">channels</a>());</div><div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;    CHECK_GE(<a class="code" href="classcaffe_1_1Blob.html#a18af535af43f4e9f85bd1e520886276f">height</a>(), 0);</div><div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;    CHECK_LE(h, <a class="code" href="classcaffe_1_1Blob.html#a18af535af43f4e9f85bd1e520886276f">height</a>());</div><div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;    CHECK_GE(<a class="code" href="classcaffe_1_1Blob.html#afbdc067c69e6b9bd6880a73c13db2ec6">width</a>(), 0);</div><div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;    CHECK_LE(w, <a class="code" href="classcaffe_1_1Blob.html#afbdc067c69e6b9bd6880a73c13db2ec6">width</a>());</div><div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;    <span class="keywordflow">return</span> ((n * <a class="code" href="classcaffe_1_1Blob.html#ae48c8e9f0a0b66b041e47bf37ed04471">channels</a>() + c) * <a class="code" href="classcaffe_1_1Blob.html#a18af535af43f4e9f85bd1e520886276f">height</a>() + h) * <a class="code" href="classcaffe_1_1Blob.html#afbdc067c69e6b9bd6880a73c13db2ec6">width</a>() + w;</div><div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;  }</div><div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;</div><div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">int</span> offset(<span class="keyword">const</span> vector&lt;int&gt;&amp; indices)<span class="keyword"> const </span>{</div><div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;    CHECK_LE(indices.size(), num_axes());</div><div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;    <span class="keywordtype">int</span> offset = 0;</div><div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; num_axes(); ++i) {</div><div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;      offset *= shape(i);</div><div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;      <span class="keywordflow">if</span> (indices.size() &gt; i) {</div><div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;        CHECK_GE(indices[i], 0);</div><div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;        CHECK_LT(indices[i], shape(i));</div><div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;        offset += indices[i];</div><div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;      }</div><div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;    }</div><div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;    <span class="keywordflow">return</span> offset;</div><div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;  }</div><div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Blob.html#a64ad51f99e88233f43a21a85ebe10284">CopyFrom</a>(<span class="keyword">const</span> <a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>&amp; source, <span class="keywordtype">bool</span> copy_diff = <span class="keyword">false</span>,</div><div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;      <span class="keywordtype">bool</span> reshape = <span class="keyword">false</span>);</div><div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;</div><div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;  <span class="keyword">inline</span> Dtype data_at(<span class="keyword">const</span> <span class="keywordtype">int</span> n, <span class="keyword">const</span> <span class="keywordtype">int</span> c, <span class="keyword">const</span> <span class="keywordtype">int</span> h,</div><div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;      <span class="keyword">const</span> <span class="keywordtype">int</span> w)<span class="keyword"> const </span>{</div><div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;    <span class="keywordflow">return</span> cpu_data()[offset(n, c, h, w)];</div><div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;  }</div><div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;</div><div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;  <span class="keyword">inline</span> Dtype diff_at(<span class="keyword">const</span> <span class="keywordtype">int</span> n, <span class="keyword">const</span> <span class="keywordtype">int</span> c, <span class="keyword">const</span> <span class="keywordtype">int</span> h,</div><div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;      <span class="keyword">const</span> <span class="keywordtype">int</span> w)<span class="keyword"> const </span>{</div><div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;    <span class="keywordflow">return</span> cpu_diff()[offset(n, c, h, w)];</div><div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;  }</div><div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;</div><div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;  <span class="keyword">inline</span> Dtype data_at(<span class="keyword">const</span> vector&lt;int&gt;&amp; index)<span class="keyword"> const </span>{</div><div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;    <span class="keywordflow">return</span> cpu_data()[offset(index)];</div><div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;  }</div><div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;</div><div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;  <span class="keyword">inline</span> Dtype diff_at(<span class="keyword">const</span> vector&lt;int&gt;&amp; index)<span class="keyword"> const </span>{</div><div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;    <span class="keywordflow">return</span> cpu_diff()[offset(index)];</div><div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;  }</div><div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;</div><div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;  <span class="keyword">inline</span> <span class="keyword">const</span> shared_ptr&lt;SyncedMemory&gt;&amp; data()<span class="keyword"> const </span>{</div><div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;    CHECK(data_);</div><div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;    <span class="keywordflow">return</span> data_;</div><div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;  }</div><div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;</div><div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160;  <span class="keyword">inline</span> <span class="keyword">const</span> shared_ptr&lt;SyncedMemory&gt;&amp; diff()<span class="keyword"> const </span>{</div><div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160;    CHECK(diff_);</div><div class="line"><a name="l00216"></a><span class="lineno">  216</span>&#160;    <span class="keywordflow">return</span> diff_;</div><div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;  }</div><div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;</div><div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;  <span class="keyword">const</span> Dtype* cpu_data() <span class="keyword">const</span>;</div><div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;  <span class="keywordtype">void</span> set_cpu_data(Dtype* data);</div><div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;  <span class="keyword">const</span> <span class="keywordtype">int</span>* gpu_shape() <span class="keyword">const</span>;</div><div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;  <span class="keyword">const</span> Dtype* gpu_data() <span class="keyword">const</span>;</div><div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;  <span class="keywordtype">void</span> set_gpu_data(Dtype* data);</div><div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;  <span class="keyword">const</span> Dtype* cpu_diff() <span class="keyword">const</span>;</div><div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;  <span class="keyword">const</span> Dtype* gpu_diff() <span class="keyword">const</span>;</div><div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;  Dtype* mutable_cpu_data();</div><div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;  Dtype* mutable_gpu_data();</div><div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;  Dtype* mutable_cpu_diff();</div><div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;  Dtype* mutable_gpu_diff();</div><div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;  <span class="keywordtype">void</span> Update();</div><div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;  <span class="keywordtype">void</span> FromProto(<span class="keyword">const</span> BlobProto&amp; proto, <span class="keywordtype">bool</span> reshape = <span class="keyword">true</span>);</div><div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;  <span class="keywordtype">void</span> ToProto(BlobProto* proto, <span class="keywordtype">bool</span> write_diff = <span class="keyword">false</span>) <span class="keyword">const</span>;</div><div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;</div><div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;  Dtype <a class="code" href="classcaffe_1_1Blob.html#aa06094adb9337a7d67f7049a1f2ede54">asum_data</a>() <span class="keyword">const</span>;</div><div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;  Dtype <a class="code" href="classcaffe_1_1Blob.html#a1bf366edeb71ae6a76d4177fef3879ec">asum_diff</a>() <span class="keyword">const</span>;</div><div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;  Dtype <a class="code" href="classcaffe_1_1Blob.html#a2ea640466fc339a02dabba4e8a1f0de2">sumsq_data</a>() <span class="keyword">const</span>;</div><div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;  Dtype <a class="code" href="classcaffe_1_1Blob.html#a2df1894f11323235f9d7c7a1f0fe010f">sumsq_diff</a>() <span class="keyword">const</span>;</div><div class="line"><a name="l00242"></a><span class="lineno">  242</span>&#160;</div><div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Blob.html#a535dd556e777f2e13b8c7438f40749a0">scale_data</a>(Dtype scale_factor);</div><div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Blob.html#a6d2d83920d961fff033434347f64a3b0">scale_diff</a>(Dtype scale_factor);</div><div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;</div><div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Blob.html#a8fce5a816a2b9629686db69108610d93">ShareData</a>(<span class="keyword">const</span> <a class="code" href="classcaffe_1_1Blob.html">Blob</a>&amp; other);</div><div class="line"><a name="l00265"></a><span class="lineno">  265</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Blob.html#a004781965b09f94c409cec9a6fc7c35c">ShareDiff</a>(<span class="keyword">const</span> <a class="code" href="classcaffe_1_1Blob.html">Blob</a>&amp; other);</div><div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160;</div><div class="line"><a name="l00267"></a><span class="lineno">  267</span>&#160;  <span class="keywordtype">bool</span> ShapeEquals(<span class="keyword">const</span> BlobProto&amp; other);</div><div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;</div><div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160; <span class="keyword">protected</span>:</div><div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;  shared_ptr&lt;SyncedMemory&gt; data_;</div><div class="line"><a name="l00271"></a><span class="lineno">  271</span>&#160;  shared_ptr&lt;SyncedMemory&gt; diff_;</div><div class="line"><a name="l00272"></a><span class="lineno">  272</span>&#160;  shared_ptr&lt;SyncedMemory&gt; shape_data_;</div><div class="line"><a name="l00273"></a><span class="lineno">  273</span>&#160;  vector&lt;int&gt; shape_;</div><div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160;  <span class="keywordtype">int</span> count_;</div><div class="line"><a name="l00275"></a><span class="lineno">  275</span>&#160;  <span class="keywordtype">int</span> capacity_;</div><div class="line"><a name="l00276"></a><span class="lineno">  276</span>&#160;</div><div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;  DISABLE_COPY_AND_ASSIGN(<a class="code" href="classcaffe_1_1Blob.html">Blob</a>);</div><div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;};  <span class="comment">// class Blob</span></div><div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;</div><div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;}  <span class="comment">// namespace caffe</span></div><div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;</div><div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;<span class="preprocessor">#endif  // CAFFE_BLOB_HPP_</span></div><div class="ttc" id="classcaffe_1_1Blob_html_ae48c8e9f0a0b66b041e47bf37ed04471"><div class="ttname"><a href="classcaffe_1_1Blob.html#ae48c8e9f0a0b66b041e47bf37ed04471">caffe::Blob::channels</a></div><div class="ttdeci">int channels() const</div><div class="ttdoc">Deprecated legacy shape accessor channels: use shape(1) instead. </div><div class="ttdef"><b>Definition:</b> blob.hpp:134</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a807f4da98e8e0d1f60badb1f540fe010"><div class="ttname"><a href="classcaffe_1_1Blob.html#a807f4da98e8e0d1f60badb1f540fe010">caffe::Blob::shape</a></div><div class="ttdeci">int shape(int index) const</div><div class="ttdoc">Returns the dimension of the index-th axis (or the negative index-th axis from the end...</div><div class="ttdef"><b>Definition:</b> blob.hpp:71</div></div>
<div class="ttc" id="namespacecaffe_html"><div class="ttname"><a href="namespacecaffe.html">caffe</a></div><div class="ttdoc">A layer factory that allows one to register layers. During runtime, registered layers can be called b...</div><div class="ttdef"><b>Definition:</b> blob.hpp:14</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a1bf366edeb71ae6a76d4177fef3879ec"><div class="ttname"><a href="classcaffe_1_1Blob.html#a1bf366edeb71ae6a76d4177fef3879ec">caffe::Blob::asum_diff</a></div><div class="ttdeci">Dtype asum_diff() const</div><div class="ttdoc">Compute the sum of absolute values (L1 norm) of the diff. </div><div class="ttdef"><b>Definition:</b> blob.cpp:245</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a004781965b09f94c409cec9a6fc7c35c"><div class="ttname"><a href="classcaffe_1_1Blob.html#a004781965b09f94c409cec9a6fc7c35c">caffe::Blob::ShareDiff</a></div><div class="ttdeci">void ShareDiff(const Blob &amp;other)</div><div class="ttdoc">Set the diff_ shared_ptr to point to the SyncedMemory holding the diff_ of Blob other – useful in La...</div><div class="ttdef"><b>Definition:</b> blob.cpp:162</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a8fce5a816a2b9629686db69108610d93"><div class="ttname"><a href="classcaffe_1_1Blob.html#a8fce5a816a2b9629686db69108610d93">caffe::Blob::ShareData</a></div><div class="ttdeci">void ShareData(const Blob &amp;other)</div><div class="ttdoc">Set the data_ shared_ptr to point to the SyncedMemory holding the data_ of Blob other – useful in La...</div><div class="ttdef"><b>Definition:</b> blob.cpp:156</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_aa06094adb9337a7d67f7049a1f2ede54"><div class="ttname"><a href="classcaffe_1_1Blob.html#aa06094adb9337a7d67f7049a1f2ede54">caffe::Blob::asum_data</a></div><div class="ttdeci">Dtype asum_data() const</div><div class="ttdoc">Compute the sum of absolute values (L1 norm) of the data. </div><div class="ttdef"><b>Definition:</b> blob.cpp:210</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a18af535af43f4e9f85bd1e520886276f"><div class="ttname"><a href="classcaffe_1_1Blob.html#a18af535af43f4e9f85bd1e520886276f">caffe::Blob::height</a></div><div class="ttdeci">int height() const</div><div class="ttdoc">Deprecated legacy shape accessor height: use shape(2) instead. </div><div class="ttdef"><b>Definition:</b> blob.hpp:136</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_ad0e0a9a4f49478e89161c6afe4e341a0"><div class="ttname"><a href="classcaffe_1_1Blob.html#ad0e0a9a4f49478e89161c6afe4e341a0">caffe::Blob::Reshape</a></div><div class="ttdeci">void Reshape(const int num, const int channels, const int height, const int width)</div><div class="ttdoc">Deprecated; use Reshape(const vector&lt;int&gt;&amp; shape). </div><div class="ttdef"><b>Definition:</b> blob.cpp:12</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a2df1894f11323235f9d7c7a1f0fe010f"><div class="ttname"><a href="classcaffe_1_1Blob.html#a2df1894f11323235f9d7c7a1f0fe010f">caffe::Blob::sumsq_diff</a></div><div class="ttdeci">Dtype sumsq_diff() const</div><div class="ttdoc">Compute the sum of squares (L2 norm squared) of the diff. </div><div class="ttdef"><b>Definition:</b> blob.cpp:317</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a6d2d83920d961fff033434347f64a3b0"><div class="ttname"><a href="classcaffe_1_1Blob.html#a6d2d83920d961fff033434347f64a3b0">caffe::Blob::scale_diff</a></div><div class="ttdeci">void scale_diff(Dtype scale_factor)</div><div class="ttdoc">Scale the blob diff by a constant factor. </div><div class="ttdef"><b>Definition:</b> blob.cpp:385</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_ad686f5ed9994046f2c741bfa81118509"><div class="ttname"><a href="classcaffe_1_1Blob.html#ad686f5ed9994046f2c741bfa81118509">caffe::Blob::CanonicalAxisIndex</a></div><div class="ttdeci">int CanonicalAxisIndex(int axis_index) const</div><div class="ttdoc">Returns the &amp;#39;canonical&amp;#39; version of a (usually) user-specified axis, allowing for negative indexing (e...</div><div class="ttdef"><b>Definition:</b> blob.hpp:118</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a64ad51f99e88233f43a21a85ebe10284"><div class="ttname"><a href="classcaffe_1_1Blob.html#a64ad51f99e88233f43a21a85ebe10284">caffe::Blob::CopyFrom</a></div><div class="ttdeci">void CopyFrom(const Blob&lt; Dtype &gt; &amp;source, bool copy_diff=false, bool reshape=false)</div><div class="ttdoc">Copy from a source Blob. </div><div class="ttdef"><b>Definition:</b> blob.cpp:433</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a2ea640466fc339a02dabba4e8a1f0de2"><div class="ttname"><a href="classcaffe_1_1Blob.html#a2ea640466fc339a02dabba4e8a1f0de2">caffe::Blob::sumsq_data</a></div><div class="ttdeci">Dtype sumsq_data() const</div><div class="ttdoc">Compute the sum of squares (L2 norm squared) of the data. </div><div class="ttdef"><b>Definition:</b> blob.cpp:280</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a535dd556e777f2e13b8c7438f40749a0"><div class="ttname"><a href="classcaffe_1_1Blob.html#a535dd556e777f2e13b8c7438f40749a0">caffe::Blob::scale_data</a></div><div class="ttdeci">void scale_data(Dtype scale_factor)</div><div class="ttdoc">Scale the blob data by a constant factor. </div><div class="ttdef"><b>Definition:</b> blob.cpp:352</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a80ed3eddf98ffd408e9a627b1a7c2a9e"><div class="ttname"><a href="classcaffe_1_1Blob.html#a80ed3eddf98ffd408e9a627b1a7c2a9e">caffe::Blob::num</a></div><div class="ttdeci">int num() const</div><div class="ttdoc">Deprecated legacy shape accessor num: use shape(0) instead. </div><div class="ttdef"><b>Definition:</b> blob.hpp:132</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_afbdc067c69e6b9bd6880a73c13db2ec6"><div class="ttname"><a href="classcaffe_1_1Blob.html#afbdc067c69e6b9bd6880a73c13db2ec6">caffe::Blob::width</a></div><div class="ttdeci">int width() const</div><div class="ttdoc">Deprecated legacy shape accessor width: use shape(3) instead. </div><div class="ttdef"><b>Definition:</b> blob.hpp:138</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_aab573b2a70c26bf3b2ae65e42706003e"><div class="ttname"><a href="classcaffe_1_1Blob.html#aab573b2a70c26bf3b2ae65e42706003e">caffe::Blob::count</a></div><div class="ttdeci">int count(int start_axis) const</div><div class="ttdoc">Compute the volume of a slice spanning from a particular first axis to the final axis. </div><div class="ttdef"><b>Definition:</b> blob.hpp:103</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a8674686a97c961b309b4420ead6626b5"><div class="ttname"><a href="classcaffe_1_1Blob.html#a8674686a97c961b309b4420ead6626b5">caffe::Blob::count</a></div><div class="ttdeci">int count(int start_axis, int end_axis) const</div><div class="ttdoc">Compute the volume of a slice; i.e., the product of dimensions among a range of axes. </div><div class="ttdef"><b>Definition:</b> blob.hpp:85</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html"><div class="ttname"><a href="classcaffe_1_1Blob.html">caffe::Blob</a></div><div class="ttdoc">A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers...</div><div class="ttdef"><b>Definition:</b> blob.hpp:24</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Thu Aug 3 2017 23:11:19 for Caffe by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
